// session数据存储
global.session = {
	set: function(key, val) {
		sessionStorage.setItem(key, JSON.stringify(val));
	},
	get: function(key) {
		return JSON.parse(sessionStorage.getItem(key));
	},
	length: sessionStorage.length,
	remove: function(key) {
		sessionStorage.removeItem(key);
	},
	clear: function() {
		sessionStorage.clear();
	}
};

// 数据字典
global.dicCache = {
	/**
	 * 获取指定mark的cache
	 * @param {String} mark 字典标识
	 */
	getCacheByMark: function(mark) {
		let cache = session.get(process.env.SESSION_KEY_DIC);
		return cache[mark];
	},
	/**
	 * 获取指定mark和value的cache-value
	 * @param {String} mark 字典标识
	 * @param {String} name 字典名称
	 */
	getValByMarkAndName: function(mark, name) {
		let dicCache = this.getCacheByMark(mark);
		if(dicCache && dicCache.length > 0) {
			let dic = dicCache.filter((x) => x.dicVal == value)[0];
			return dic ? dic['dicVal'] : null;
		} else {
			return null;
		}
	},
	/**
	 * 获取指定mode和value的cache-name
	 * @param {String} mark 字典标识
	 * @param {String} value 字典值
	 */
	getNameByMarkAndVal: function(mark, value) {
		let dicCache = this.getCacheByMark(mark);
		if(dicCache && dicCache.length > 0) {
			let dic = dicCache.filter((x) => x.dicVal == value)[0];
			return dic ? dic['dicName'] : null;
		} else {
			return null;
		}
	}
};